<?php
 class phpinchains_parser_el_ELCallBack
{

    var $dict = array();
    var $tree;

    function shift ($token, $stack)
    {
        $this->dict[$token['type']][] = $token;
    }

    function reduce ($no, $rule, $stack)
    {
        $tokens = array();
        for ($i = count($rule[1])-1; $i > -1; $i--)
        {
            array_unshift($tokens, array_pop($this->dict[$rule[1][$i]]));
        }
        $this->dict[$rule[0]][] = $this->reduceAction($no, $tokens);
    }

    function reset()
    {
        unset ($this->dict);
        $this->dict = array();
    }
    
    function getAST ()
    {
        return $this->tree;
    }
    function reduceAction ($rule, $tokens) {
       switch ($rule) {
         case 0: 
            $this->tree = $tokens[0];
            break;
         case 1: 
             return new Code($tokens[0]); 
            break;
         case 2: 
             return new OuterString($tokens[0]['value']); 
            break;
         case 3: 
             return new ELPart($tokens[0], $tokens[1]); 
            break;
         case 4: 
             return $tokens[1]; 
            break;
         case 5: 
             return $tokens[1]; 
            break;
         case 6: 
             return new PlusExpr($tokens[0], $tokens[2]); 
            break;
         case 7: 
             return new MinusExpr($tokens[0], $tokens[2]); 
            break;
         case 8: 
             return new NegNumber($tokens[1]['value']); 
            break;
         case 9: 
             return new MultExpr($tokens[0], $tokens[2]); 
            break;
         case 10: 
             return new ModExpr($tokens[0], $tokens[2]); 
            break;
         case 11: 
             return new DivExpr($tokens[0], $tokens[2]); 
            break;
         case 12: 
             return new ConcatExpr($tokens[0], $tokens[2]); 
            break;
         case 13: 
             return new ParenExpr($tokens[1]); 
            break;
         case 14: 
             return new FunExpr($tokens[1]['value'], $tokens[3]); 
            break;
         case 15: 
             return $tokens[0]; 
            break;
         case 16: 
             return $tokens[0]; 
            break;
         case 17: 
             return new Digit($tokens[0]['value']); 
            break;
         case 18: 
             return new String($tokens[0]['value']); 
            break;
         case 19: 
             return new TrueKeyword($tokens[0]['value']); 
            break;
         case 20: 
             return new FalseKeyword($tokens[0]['value']); 
            break;
         case 21: 
             return new ParamPair($tokens[0], new Param($tokens[2])); 
            break;
         case 22: 
             return new Param($tokens[0]); 
            break;
         case 23: 
             return $tokens[0]; 
            break;
         case 24: 
             return new VarArray($tokens[0], $tokens[1]); 
            break;
         case 25: 
             return new IdPair($tokens[0], new Id($tokens[2]['value'])); 
            break;
         case 26: 
             return new IdPair($tokens[0], new IdPair(new Id($tokens[2]['value']), $tokens[3])); 
            break;
         case 27: 
             return new Id($tokens[0]['value']); 
            break;
         case 28: 
             return new IdPair(new Id($tokens[0]['value']), $tokens[1]); 
            break;
         case 29: 
             return new Variable($tokens[1]['value']); 
            break;
         case 30: 
             return new ArrayPair($tokens[0], new ArrayT($tokens[2])); 
            break;
         case 31: 
             return new ArrayT($tokens[1]); 
            break;
         case 32: 
             return new Negation($tokens[1]); 
            break;
         case 33: 
             return new Negation($tokens[1]); 
            break;
         case 34: 
             return new Negation(new Digit($tokens[1]['value'])); 
            break;
         case 35: 
             return new Negation(new String($tokens[1]['value'])); 
            break;
         case 36: 
             return new Negation($tokens[2]); 
            break;
         case 37: 
             return $tokens[0]; 
            break;
         case 38: 
             return new ParenExpr($tokens[1]); 
            break;
         case 39: 
             return new EqExpr($tokens[0], $tokens[2]); 
            break;
         case 40: 
             return new NeqExpr($tokens[0], $tokens[2]); 
            break;
         case 41: 
             return new LeqExpr($tokens[0], $tokens[2]); 
            break;
         case 42: 
             return new GeqExpr($tokens[0], $tokens[2]); 
            break;
         case 43: 
             return new GtExpr($tokens[0], $tokens[2]); 
            break;
         case 44: 
             return new LtExpr($tokens[0], $tokens[2]); 
            break;
         case 45: 
             return new OrExpr($tokens[0], $tokens[2]); 
            break;
         case 46: 
             return new EOrExpr($tokens[0], $tokens[2]); 
            break;
         case 47: 
             return new AndExpr($tokens[0], $tokens[2]); 
            break;
         case 48: 
             return new EAndExpr($tokens[0], $tokens[2]); 
            break;
         case 49: 
             return new ConditionalExpr($tokens[0], $tokens[2], $tokens[4]); 
            break;
       }
    }
}
 
?>